package qc.module.ehs.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.ehs.dto.certificate.CertificateDto;
import qc.module.ehs.dto.certificate.CertificateQueryConditionDto;
import qc.module.ehs.service.EhsCertificateInfoService;

import java.util.List;

/**
 * CertificateInfoController
 * @author YRR
 * @create 2025-03-11 13:28
 */
@RestController
@RequestMapping("/certificate")
public class CertificateInfoController {

    @Autowired
    private EhsCertificateInfoService Service;

    /**
     * 查询资质证照信息
     * @param dto 查询条件的信息
     * @return List<CertificateDto>
     * @throws QCPromptException
     */
    @RequestMapping(value = "/query", method = {RequestMethod.GET, RequestMethod.POST})
    public List<CertificateDto> query(@RequestBody CertificateQueryConditionDto dto) throws QCPromptException {
        return Service.query(dto);
    }

    /**
     * 新增资质证照信息
     * @param dto 新增的信息
     * @return 成功返回null，失败返回错误或提示信息
     * @throws QCPromptException
     */
    @RequestMapping(value = "/add", method = {RequestMethod.POST, RequestMethod.PUT})
    public String add(@RequestBody CertificateDto dto) throws QCPromptException {
        return Service.add(dto);
    }

    /**
     * 修改资质证照信息
     * @param dto 修改的信息
     * @return 成功返回null，失败返回错误或提示信息
     */
    @RequestMapping(value = "/update", method = {RequestMethod.PUT, RequestMethod.POST})
    public String update(@RequestBody CertificateDto dto) {
        return Service.update(dto);
    }

    /**
     * 删除指定的资质证照信息
     * @param id 资质证照id
     * @return 成功返回null，失败返回错误或提示信息
     */
    @DeleteMapping("/delete")
    public String deleteByParam(@RequestParam(value = "id", required = true) String id) {
        return Service.delete(id);
    }

    /**
     * 删除指定的资质证照信息
     * @param id 资质证照id
     * @return 成功返回null，失败返回错误或提示信息
     */
    @DeleteMapping("/delete/{id}")
    public String deleteByPath(@PathVariable(value = "id", required = true) String id) {
        return Service.delete(id);
    }

    /**
     * 获取指定的资质证照信息
     * @param id 资质证照id
     * @return CertificateDto
     * @throws QCPromptException
     */
    @GetMapping("/get")
    public CertificateDto getByParam(@RequestParam(value = "id", required = true) String id) throws QCPromptException {
        return Service.get(id);
    }

    /**
     * 获取指定的资质证照信息
     * @param id 资质证照id
     * @return CertificateDto
     * @throws QCPromptException
     */
    @GetMapping("/get/{id}")
    public CertificateDto getByPath(@PathVariable(value = "id", required = true) String id) throws QCPromptException {
        return Service.get(id);
    }


}
